var user = JSON.parse(localStorage.getItem("user"));
console.log(localStorage.getItem("user"));
//获取token
var token = localStorage.getItem("token");

function infoValue() {
	if(user) {
		hui('.userPhone').html(user.phone);
		hui('.realname').html(user.realname);
		hui('.age').html(user.age);
		hui('.idcad').html(user.idcard);
		hui('.street').html(user.street);
		hui('.address').html(user.address);
		hui('.nowPhone').html(user.nowPhone);
		hui('.nowPhone').html(user.nowName);
	}
}

//签约
function perfectuser() {
	var datainfo = {
			'token': token,
			'street': hui('.street').html(),
			'address': hui('.nowPhone').html(),
			'contactsPhone': hui('.address').html(),
			'contacts': hui('.nowName').html()
		}
		console.log(JSON.stringify(datainfo));
		hui.ajax({
			type: 'POST',
			url: globleobj['domain'] + '/residents/perfectuser',
			data: datainfo,
			beforeSend: function() {
				hui.loading();
			},
			complete: function() {
				hui.closeLoading();
			},
			success: function(msg) {
				console.log('perfectuser' + msg)
				var data = JSON.parse(msg);
				if(data.rc != 0) {
					hui.toast(data.msg);
					return false;
				}

				hui.iconToast('信息修改成功！');
				
				setTimeout(function(){
					hui.open('personcenter.html',{},true);
				},1000);

			},
			error: function(e) {
				console.log(JSON.stringify(e));
				hui.iconToast('读取消息失败', 'warn');
			}
		});
}

hui.ready(function() {
	infoValue();

	hui('.fixedInfo').click(function() {
		var thatDom = hui(this);
		var content=hui(this).find(".hui-list-text-content").html();
		console.log(content)
		hui.prompt('请输入您要更改的'+content+'？', ['取消', '确定'], function(name) {
			console.log('您输入了 :' + name);
			thatDom.find(".hui-list-info").html(name);
		}, '', '', function() {
			console.log('您点击了取消')
		});
	});

	hui('#submitBtn').click(function() {
		perfectuser();
	});

	//	//跳转个人中心
	//	hui('#nav-my').click(function(){
	//	    hui.open('personcenter.html')
	//	});
	hui.plusReady(function() {
		console.log('plusReady')
	});
});